﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;

namespace OpenAdmin.Core.Models.Mall;

/// <summary>
/// 分类、产品关系表
/// </summary>
[Table("CategoryProducts")]
public class CategoryProduct : EntityRelation<MallDbContextLocator>, IEntityTypeConfigure<CategoryProduct>, IEntityTypeSeedDataConfigure<CategoryProduct>
{
    /// <summary>
    /// 分类Id
    /// </summary>
    public int CategoryId { get; set; }

    /// <summary>
    /// 产品Id
    /// </summary>
    public int ProductId { get; set; }

    public void Configure(EntityTypeBuilder<CategoryProduct> entityBuilder)
    {
        entityBuilder.HasKey(x => new { x.CategoryId, x.ProductId });
    }

    public IEnumerable<CategoryProduct> HasData(DbContext dbContext)
    {
        return new List<CategoryProduct>() {
            new CategoryProduct { CategoryId = 1, ProductId = 1 },
            new CategoryProduct { CategoryId = 1, ProductId = 2 },
            new CategoryProduct { CategoryId = 1, ProductId = 3 },
            new CategoryProduct { CategoryId = 2, ProductId = 4 },
            new CategoryProduct { CategoryId = 2, ProductId = 5 },
            new CategoryProduct { CategoryId = 2, ProductId = 6 },
            new CategoryProduct { CategoryId = 3, ProductId = 7 },
            new CategoryProduct { CategoryId = 3, ProductId = 8 },
            new CategoryProduct { CategoryId = 2, ProductId = 1 },
            new CategoryProduct { CategoryId = 3, ProductId = 2 },
            new CategoryProduct { CategoryId = 3, ProductId = 4 },
            new CategoryProduct { CategoryId = 1, ProductId = 7 }
        };
    }
}
